<?php
declare (strict_types = 1);

namespace app\admin\model;

class SettingModel extends Base
{
   protected $name='sysconfig';
   /**
    * 专用于前台展现
    */
   public static function getConfig(){
   		if(cache('config')){
   			return cache('config');
   		}
   		return self::setConfig();
   }

   public static function setConfig(){
   		$config=self::column('value,name,type,id');
   		$list=[];
   		foreach ($config as $k => &$v) {
   			$list[$v['type']][$v['name']]=$v['value'];
   		}
   		cache('config',$list);
   		return $list;
   }

   public static function getSetting(){
   		if(cache('setting')){
   			return cache('setting');
   		}
   		return self::setSetting();
   }

   public static function setSetting(){
   		$setting=self::column('value,name,type,id');
   		$list=[];
   		$config=[];
   		foreach ($setting as $k => &$v) {
   			$list[$v['type']][$v['name']]=$v;
   			$config[$v['type']][$v['name']]=$v['value'];
   		}
   		cache('config',$config);
   		cache('setting',$list);
   		return $list;
   }
}
